#include "wxssingleinstancechecker.h"
#include "../wxsitemresdata.h"
#include <wx/snglinst.h>

namespace {
  wxsRegisterItem<wxsSingleInstanceChecker> Reg( _T( "SingleInstanceChecker" ), _T( "SingleInstanceChecker" ), wxsTTool, _T( "工具" ), 50, false );
}

wxsSingleInstanceChecker::wxsSingleInstanceChecker( wxsItemResData* Data ):
  wxsTool( Data, &Reg.Info, 0, 0 ) {
}

void wxsSingleInstanceChecker::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
  case wxsCPP: {
    AddHeader( _T( "<wx/utils.h>" ),   GetInfo().ClassName, 0 );
    AddHeader( _T( "<wx/snglinst.h>" ), GetInfo().ClassName, 0 );
    if( AppName.IsEmpty() ) {
      AddHeader( _T( "<wx/app.h>" ), GetInfo().ClassName, 0 );
      Codef( _T( "%C(wxTheApp->GetAppName() + _T(\"_\") + wxGetUserId() + _T(\"_Guard\"));\n" ) );
    } else
    { Codef( _T( "%C(%n + wxGetUserId() + _T(\"_Guard\"));\n" ), ( AppName + _T( "_" ) ).wx_str() ); }
    BuildSetupWindowCode();
    break;
  }
  case wxsUnknownLanguage:
  default: {
    wxsCodeMarks::Unknown( _T( "wxsSingleInstanceChecker::OnBuildCreatingCode" ), GetLanguage() );
  }
  }
}

void wxsSingleInstanceChecker::OnEnumToolProperties( M_Code_unused long Flags ) {
  WXS_SHORT_STRING( wxsSingleInstanceChecker, AppName, _T( "Custom app name" ), _T( "appname" ), wxEmptyString, false );
}
